package com.example.educationalsystem.common.security.handler;


import com.example.educationalsystem.common.util.ResponseJson;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 用户未登录处理类
 */
@Component
public class UserAuthenticationEntryPointHandler implements AuthenticationEntryPoint {
    /**
     * 用户未登录返回结果
     */
    @Override
    public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) {
        //ResultUtil.responseJson(response, ResultUtil.resultCode(401,"未登录"));

        ResponseJson responseJson = new ResponseJson();
        responseJson.setStatus(401);
        responseJson.setMsg("未登录");
        ResponseJson.responsHandlerJson(response, responseJson);
    }
}
